import '../../public.dart';

/* ========== 组件 ========== */
class HomeCardItem extends StatelessWidget {
  final SysGiftCardCategoryEntity item;
  final SysGiftCardTypeEntity type;

  const HomeCardItem({super.key, required this.item, required this.type});

  @override
  Widget build(BuildContext context) {
    return Material(
      color: Colors.transparent,
      child: InkWell(
        borderRadius: BorderRadius.circular(10),
        onTap: () {
          RouterHelper.navigator.pushNamed(
            Routers.sellGiftCardDetail,
            arguments: {
              'cardTypeId': type.id,
              'cardTypeName': type.typeName ?? '',
              'category': item,
            },
          );
        },
        child: Container(
          width: ScreenUtil.width,
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
          margin: const EdgeInsets.symmetric(vertical: 8),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(10),
            boxShadow: [
              BoxShadow(
                color: Colors.black12,
                blurRadius: 12,
                offset: const Offset(0, 4),
              ),
            ],
          ),
          child: Row(
            children: [
              Container(
                width: 56,
                height: 56,
                decoration: BoxDecoration(
                  color: Colors.grey[100],
                  borderRadius: BorderRadius.circular(12),
                  boxShadow: [
                    BoxShadow(
                      color: Colors.black12,
                      blurRadius: 6,
                      offset: const Offset(0, 2),
                    ),
                  ],
                ),
                clipBehavior: Clip.antiAlias,
                child: CryptoUtil.decryptData(type.iconUrl)?.isNotEmpty == true
                    ? Image.network(
                        CryptoUtil.decryptData(type.iconUrl)!,
                        width: 56,
                        height: 56,
                        fit: BoxFit.cover,
                        errorBuilder: (context, error, stackTrace) {
                          return const Icon(
                            Icons.category,
                            size: 32,
                            color: Colors.grey,
                          );
                        },
                      )
                    : const Icon(Icons.category, size: 32, color: Colors.grey),
              ),
              const SizedBox(width: 14),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Text(
                      item.categoryName ?? 'Unknown Category',
                      style: const TextStyle(
                        fontSize: 16,
                        fontWeight: FontWeight.w700,
                      ),
                    ),
                    const SizedBox(height: 6),
                    Text(
                      type.typeName ?? '',
                      style: TextStyle(fontSize: 13, color: Colors.grey[600]),
                      overflow: TextOverflow.ellipsis,
                    ),
                  ],
                ),
              ),
              const SizedBox(width: 8),
              OutlinedButton.icon(
                onPressed: () {
                  RouterHelper.navigator.pushNamed(
                    Routers.sellGiftCardDetail,
                    arguments: {
                      'cardTypeId': type.id,
                      'cardTypeName': type.typeName ?? '',
                      'category': item,
                    },
                  );
                },
                icon: const Icon(Icons.local_offer, size: 16),
                label: const Text('Sell', style: TextStyle(fontSize: 14)),
                style: OutlinedButton.styleFrom(
                  foregroundColor: Colors.blue,
                  side: BorderSide(color: Colors.blue.shade300),
                  padding: const EdgeInsets.symmetric(
                    horizontal: 12,
                    vertical: 8,
                  ),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(8),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  // Component simplified: only icon, category name and sell button.
}
